package com.ncu.cloundeoffice.controller;

import com.ncu.cloundeoffice.pojo.ResponseResult;
import com.ncu.cloundeoffice.pojo.TAdmin;
import com.ncu.cloundeoffice.pojo.TRole;
import com.ncu.cloundeoffice.service.TAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/admin")
public class TAdminController {


    @Autowired
    private TAdminService tAdminService;

    /**
     * 获取所有操作员
     * @param keyword
     * @return
     */
    @GetMapping("/")
    public List<TAdmin> getAllTAdmins(@RequestParam(value = "keyword",defaultValue = "") String keyword){
        return tAdminService.getAllTAdmins(keyword);
    }

    /**
     * 修改操作员
     * @param tAdmin
     * @return
     */
    @PutMapping("/")
    public ResponseResult updateTAdmin(@RequestBody TAdmin tAdmin){

        return tAdminService.updateTAdmin(tAdmin);
    }

    /**
     * 删除操作员
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteTAdmin(@PathVariable("id") int id){
        return tAdminService.deleteTAdmin(id);
    }


    /**
     * 获取所有的角色
     * @return
     */
    @GetMapping("/role")
    public List<TRole> getAllRoles(){
        return tAdminService.getAllRoles();
    }


    /**
     * 更新操作员角色
     * @param adminId
     * @param rids
     * @return
     */
    @PutMapping("/role")
    public ResponseResult updateTAdminRole(@RequestParam("adminId") int adminId,
                                          @RequestParam("rids") int[] rids){
        return tAdminService.updateTAdminRole(adminId,rids);
    }

}
